package com.正则表达式;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Regex {
    public static void main(String[] args) {
        List<String> nameList = Arrays.asList("张三","李子","王麻子");
        String name = nameList.stream().collect(Collectors.joining(","));
        String patten = ".*张三.*";
        System.out.println("名字匹配");
        System.out.println(Pattern.matches(patten,name));
        List numberList = Arrays.asList("1","2","3","5");
        String number = (String) numberList.stream().collect(Collectors.joining());
        System.out.println("数字匹配");
        String numberPatten = ".*[8-9].*";
        System.out.println(Pattern.matches(numberPatten,number));
        System.out.println("1、需求： 将“我我我、、、我我、、我要、我要要、、、要要要、、要要、、学学学、、、、学学编、、、学编编编、、编编编程、、程程”还原成：我要学编程");
        String temp = "我我我、、、我我、、我要、要要、、、要要要、、要要、、学学学、、、、学学编、、、编编编、、编编编程、、程程";
        temp=temp.replaceAll("(、+)","");
        temp=temp.replaceAll("(.)\\1+", "$1");
        System.out.println(temp);
        System.out.println("检测eail地址");
        String mail="zsy@sina.com.cn";
        String regex="\\w+@[a-zA-Z0-9]+(\\.[a-zA-Z]{2,3}){1,2}";//注意：这种匹配方式适用于国内部分邮件地址，不能匹配所有的邮件
        boolean b=mail.matches(regex);
        System.out.println(mail+" is  "+b);


    }
}
